package com.agv.core.lectorDeGlobalizadoresImpl;

import java.io.File;
import java.io.FilenameFilter;

public class AccionesDeCarpetas {

	final String facturados = "C:/Documents and Settings/casa/Mis documentos/agv/ArchivosGDS/prueba/facturados";
	final String cancelados = "C:/Documents and Settings/casa/Mis documentos/agv/ArchivosGDS/prueba/cancelados";
	final String errores = "C:/Documents and Settings/casa/Mis documentos/agv/ArchivosGDS/prueba/errores";

	final String raiz = "C:/Documents and Settings/casa/Mis documentos/agv/ArchivosGDS";


	public String[] contenido(){
		File dir = new File(raiz);		
		String[] children = dir.list();

		FilenameFilter filter = new FilenameFilter() {
			public boolean accept(File dir, String name) {
				return 
//				name.endsWith("bca")||
//				name.endsWith("Txt")||
//				name.endsWith("PNR")||
				name.endsWith("dat")
				;
			}
		};

		children = dir.list(filter);

		for (int i=0; i<children.length; i++) {
			System.out.println(children[i]);
		}
		return children;

	}

	public void mover(String estado, String archivo){
		String arch = raiz+"/"+archivo;
		File dir = new File(arch);
		File dirs;	
		System.out.println("dir: "+arch+" \nexiste? "+dir.exists());
		// File (or directory) to be moved
		File file = new File(arch);

		// Destination directory
		if (estado == "facturado"){
			dirs = new File(facturados);
		}else if(estado == "cancelados"){
			dirs = new File(cancelados);
		}else{
			dirs = new File(errores);
		}
		// Move file to new directory
		boolean success = file.renameTo(new File(dirs, file.getName()));
		if (!success) {
			// File was not successfully moved
		}

	}

}
